package ClassesAndObjects;

import java.util.Scanner;

public class Work {
    public static void main(String[] args) {

    }

    public static void main8(String[] args) {
        System.out.println(primeNumber(7));
    }

    public static boolean primeNumber(int num) {
        for (int i = 2; i <= Math.sqrt((double)num); i++) {
            if(num % i == 0) {
                return false;
            }
        }
            return true;
    }

    public static void main7(String[] args) {
        System.out.println(sum(1, 2));
        System.out.println(sum(1.2, 2.2, 3.3));
    }

    public static int sum(int x,int y) {
        return x+y;
    }

    public static double sum(double x,double y,double z) {
        return x+y+z;
    }


    public static void main6(String[] args) {
        System.out.println(fibFun(5));
    }

    public static long fibFun(int num) {
        if(num <= 2) {
            return 1;
        }
        else {
            return fibFun(num-2) + fibFun(num-1);
        }
    }

    public static void main5(String[] args) {
        System.out.println(fibonacciNumber(6));
    }

    public static int fibonacciNumber(int num) {
        if(num == 1) {
            return 1;
        }
        if(num == 2) {
            return 1;
        }
        int fib1 = 1;
        int fib2 = 1;
        int fib3 = -1;
        while(num >= 3) {
            fib3 = fib2 + fib1;
            fib1 = fib2;
            fib2 = fib3;
            num--;
        }
        return fib3;
    }

    public static void main4(String[] args) {
        System.out.println(fun(5));
    }

    public static long fun(int f) {
        long factorial = 1;
        long sum = 0;
        for (int i = 1; i <= f; i++) {
            factorial *= i;
            sum += factorial;
        }
        return sum;
    }

    public static void main3(String[] args) {
        System.out.println(maxNumber2(4, 5));
        System.out.println(maxNumber3(1, 2, 3));
    }

    public static int maxNumber2(int x,int y) {
        return x > y ? x : y;
    }
    public static int maxNumber3(int x,int y,int z) {
        int max2 = maxNumber2(x,y);
        return max2 > z ? max2 : z;
    }






    public static void main2(String[] args) {
        //创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
        //要求：在max3这个函数中，调用max2函数，来实现3个数的最大值
        int[] array = {3,4};
        System.out.println(maxNum(array));

    }

    public static int maxNum(int[] array) {
        int max = 0 ;
        for (int i = 1; i < array.length; i++) {
            if(array[i-1]>array[i]) {
                max = array[i-1];
            }
            else {
                max = array[i];
            }
        }
        return max;
    }


    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if((i == j) || i + j == (n - 1)) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}
